<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<body>
<!--定义按钮-->
<input type="button" onClick="on()" value="开灯">
<img id="myImage" border="0" src="sc/on.gif" style="text-align:center;">
<input type="button" onClick="off()" value="关灯">

<script>
	//on函数更换图片为开灯
    function on(){
        document.getElementById('myImage').src='sc/on.gif';
    }

	//off函数更换图片为关灯
    function off(){
        document.getElementById('myImage').src='sc/off.gif';
    }

    //设置计数
    let x = 0;
    //开启定时器
    setInterval(function (){
        //判断
        if (x%2===0){
            on();
        }else {
            off();
        }
        //修改x
        x++;
    },1000)
</script>

</body>
</html>